/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewSOFrame.java
 *
 * Created on Feb 9, 2011, 9:50:57 AM
 */

package gbbmgmt;

import org.jdesktop.application.Action;
import java.util.*;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class NewSOFrame extends javax.swing.JFrame {

    public ArrayList<String[]> Customers;
    public ArrayList<String[]> Beers;
    public ArrayList<String[]> Discounts;

    String OrderCSV = "";
    String OrderText = "";

    /** Creates new form NewSOFrame */
    public NewSOFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desertRed1 = new com.jgoodies.looks.plastic.theme.DesertRed();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldNumHalf = new javax.swing.JTextField();
        jTextFieldNum22 = new javax.swing.JTextField();
        jTextFieldNumQtr = new javax.swing.JTextField();
        jTextFieldNum12 = new javax.swing.JTextField();
        jTextFieldNumSix = new javax.swing.JTextField();
        jTextFieldNum750 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jSeparator3 = new javax.swing.JSeparator();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jButtonReset = new javax.swing.JButton();
        jComboBoxCustomers = new javax.swing.JComboBox();
        jComboBoxBeer = new javax.swing.JComboBox();
        jComboBoxDiscount = new javax.swing.JComboBox();
        jButtonOverRide = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        setResizable(false);

        jDateChooser1.setName("jDateChooser1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(NewSOFrame.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(NewSOFrame.class, this);
        jButton1.setAction(actionMap.get("AddToOrder")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jTextFieldNumHalf.setText(resourceMap.getString("jTextFieldNumHalf.text")); // NOI18N
        jTextFieldNumHalf.setName("jTextFieldNumHalf"); // NOI18N

        jTextFieldNum22.setText(resourceMap.getString("jTextFieldNum22.text")); // NOI18N
        jTextFieldNum22.setName("jTextFieldNum22"); // NOI18N

        jTextFieldNumQtr.setName("jTextFieldNumQtr"); // NOI18N

        jTextFieldNum12.setName("jTextFieldNum12"); // NOI18N

        jTextFieldNumSix.setName("jTextFieldNumSix"); // NOI18N

        jTextFieldNum750.setName("jTextFieldNum750"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        jSeparator3.setName("jSeparator3"); // NOI18N

        jButton2.setAction(actionMap.get("ExitNewSO")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setAction(actionMap.get("SubmitSO")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jButtonReset.setAction(actionMap.get("ResetData")); // NOI18N
        jButtonReset.setText(resourceMap.getString("jButtonReset.text")); // NOI18N
        jButtonReset.setName("jButtonReset"); // NOI18N

        jComboBoxCustomers.setName("jComboBoxCustomers"); // NOI18N
        jComboBoxCustomers.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxCustomersPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        jComboBoxBeer.setName("jComboBoxBeer"); // NOI18N
        jComboBoxBeer.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxBeerPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        jComboBoxDiscount.setName("jComboBoxDiscount"); // NOI18N

        jButtonOverRide.setAction(actionMap.get("OverRide")); // NOI18N
        jButtonOverRide.setText(resourceMap.getString("jButtonOverRide.text")); // NOI18N
        jButtonOverRide.setName("jButtonOverRide"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonReset)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonOverRide)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 267, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel9)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldNum22, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldNumHalf, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldNum12, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldNumQtr, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldNum750, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldNumSix, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(jButton1))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxDiscount, 0, 150, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxCustomers, 0, 372, Short.MAX_VALUE))
                            .addComponent(jComboBoxBeer, 0, 564, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldNum12, jTextFieldNum22, jTextFieldNum750, jTextFieldNumHalf, jTextFieldNumQtr, jTextFieldNumSix});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBoxCustomers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxBeer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldNumHalf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldNumQtr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldNumSix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jComboBoxDiscount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldNum22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldNum12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldNum750, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButtonReset)
                    .addComponent(jButtonOverRide))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxCustomersPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxCustomersPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        // Add code to enable only what is on hand....
        
    }//GEN-LAST:event_jComboBoxCustomersPopupMenuWillBecomeInvisible

    private void jComboBoxBeerPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxBeerPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        ResetValues();

        String sel = jComboBoxBeer.getSelectedItem().toString();
        String BeerID = "0";

        for(String s[] : Beers){
            if (s[1].equals(sel)) {
                BeerID = s[0];
            }
        }

        DBA.openDBCon();

        //Check inventory of beer to see what to enable and what not to.
        String BIID = DBA.ReturnKey("BeerInventory", "BIBId", BeerID, "BIId");

        DBA.GetBeerInventoryData(BIID);

        DBA.closeDBCon();

        if(DBA.BIHalf > 0){
            jTextFieldNumHalf.setEnabled(true);
        }
        if(DBA.BIQtr > 0){
            jTextFieldNumQtr.setEnabled(true);
        }
        if(DBA.BISix > 0){
            jTextFieldNumSix.setEnabled(true);
        }
        if(DBA.BITT > 0){
            jTextFieldNum22.setEnabled(true);
        }
        if(DBA.BITW > 0){
            jTextFieldNum12.setEnabled(true);
        }
        if(DBA.BISF > 0){
            jTextFieldNum750.setEnabled(true);
        }

    }//GEN-LAST:event_jComboBoxBeerPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewSOFrame().setVisible(true);
            }
        });
    }

    @Action
    public void ExitNewSO() {
        dispose();
    }

    public void LoadList(){
        DBA.openDBCon();
        Customers = DBA.RunSQLQuery("SELECT CId,CName FROM Customer WHERE CId != '14' AND CId != '15' ORDER BY CName ASC");
        Beers = DBA.RunSQLQuery("SELECT BId,BName FROM Beer WHERE InProduction='1'");
        Discounts = DBA.RunSQLQuery("SELECT DiscID,DiscName FROM DiscountCode");
        DBA.closeDBCon();

        for(String s[] : Customers){
            jComboBoxCustomers.addItem(s[1]);
        }

        jComboBoxBeer.addItem("");
        for(String s[] : Beers){
            jComboBoxBeer.addItem(s[1]);
        }

        for(String s[] : Discounts){
            jComboBoxDiscount.addItem(s[1]);
        }

        //Get todays date.
        java.util.Date dt = new java.util.Date();
        //java.sql.Date todaysdate = new java.sql.Date( dt.getTime());
        jDateChooser1.setDate(dt);

        jComboBoxCustomers.setSelectedIndex(0);
        jComboBoxBeer.setSelectedIndex(0);
        jComboBoxDiscount.setSelectedIndex(0);

        SetData();

    }

    public void SetData(){
        jComboBoxBeer.setSelectedIndex(0);
        jTextFieldNumHalf.setText("0");
        jTextFieldNumQtr.setText("0");
        jTextFieldNumSix.setText("0");
        jTextFieldNum22.setText("0");
        jTextFieldNum12.setText("0");
        jTextFieldNum750.setText("0");
        ResetValues();
    }

    @Action
    public void AddToOrder() {
        String ItmCust = jComboBoxCustomers.getSelectedItem().toString();
        String ItmBeer = jComboBoxBeer.getSelectedItem().toString();
        String ItmDisc = jComboBoxDiscount.getSelectedItem().toString();

        String BeerID = null;
        String CustID = null;
        String DiscID = null;

        //Set All Variables for addint to strings.
        for(String s[] : Customers){
            if (s[1].equals(ItmCust)) {
                CustID = s[0];
            }
        }

        for(String s[] : Beers){
            if (s[1].equals(ItmBeer)) {
                BeerID = s[0];
            }
        }

        for(String s[] : Discounts){
            if (s[1].equals(ItmDisc)) {
                DiscID = s[0];
            }
        }
        
        String NumHalf = jTextFieldNumHalf.getText();
        String NumQtr = jTextFieldNumQtr.getText();
        String NumSix = jTextFieldNumSix.getText();
        String Num22 = jTextFieldNum22.getText();
        String Num12 = jTextFieldNum12.getText();
        String Num750 = jTextFieldNum750.getText();

        int nhlf = Integer.parseInt(NumHalf);
        int nqtr = Integer.parseInt(NumQtr);
        int nsix = Integer.parseInt(NumSix);
        int n012 = Integer.parseInt(Num12);
        int n022 = Integer.parseInt(Num22);
        int n750 = Integer.parseInt(Num750);

        boolean orderkosher = true;

        if (nhlf > DBA.BIHalf) orderkosher = false;
        if (nqtr > DBA.BIQtr) orderkosher = false;
        if (nsix > DBA.BISix) orderkosher = false;
        if (n022 > DBA.BITT) orderkosher = false;
        if (n012 > DBA.BITW) orderkosher = false;
        if (n750 > DBA.BISF) orderkosher = false;

        if (ItmBeer.equals("")) orderkosher = false;

        if (orderkosher == false){
            int response = JOptionPane.showConfirmDialog(null,
                "Check order, not enough beer in stock!",
                "Warning",JOptionPane.WARNING_MESSAGE);

            return;
        }

        //Perform database queries.
        DBA.openDBCon();
        DBA.GetBeerData(BeerID);
        DBA.GetCustomerData(CustID);
        DBA.GetDiscountCodeData(DiscID);
        DBA.GetEmployeeData(Integer.toString(Global.userID));
        DBA.closeDBCon();

        if (!jTextFieldNumHalf.getText().equals("0") ||
                !jTextFieldNumQtr.getText().equals("0") ||
                !jTextFieldNumSix.getText().equals("0") ||
                !jTextFieldNum22.getText().equals("0") ||
                !jTextFieldNum12.getText().equals("0") ||
                !jTextFieldNum750.getText().equals("0")){
            OrderText += DBA.BName + " - ";

            if (!jTextFieldNumHalf.getText().equals("0")){
                OrderText += jTextFieldNumHalf.getText() + "x 1/2 BBL Keg(s), ";
            }
            if (!jTextFieldNumQtr.getText().equals("0")){
                OrderText += jTextFieldNumQtr.getText() + "x 1/4 BBL Keg(s), ";
            }
            if (!jTextFieldNumSix.getText().equals("0")){
                OrderText += jTextFieldNumSix.getText() + "x 1/6 BBL Keg(s), ";
            }
            if (!jTextFieldNum22.getText().equals("0")){
                OrderText += jTextFieldNum22.getText() + "x 22 Oz. Case(s), ";
            }
            if (!jTextFieldNum12.getText().equals("0")){
                OrderText += jTextFieldNum12.getText() + "x 12 Oz. Case(s), ";
            }
            if (!jTextFieldNum750.getText().equals("0")){
                OrderText += jTextFieldNum750.getText() + "x 750 mL Case(s), ";
            }

            if (!DBA.DiscName.equals("None")){
                OrderText += "Discount: " + DBA.DiscName;
            }

            OrderText += "\n";

            jTextArea1.setText(OrderText);
            jComboBoxDiscount.setSelectedItem(0);


            //Add info to the Sales Order CSV.
            OrderCSV += BeerID + "," + NumHalf + "," + NumQtr +
                    "," + NumSix + "," + DiscID + "," + Num22 + "," + Num12 +
                    "," + Num750 + ",";
        }
        
        SetData();

    }

    @Action
    public void ResetData() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will reset current Sales Order, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            SetData();
            OrderText = "";
            OrderCSV = "";
            jTextArea1.setText(OrderText);
            jComboBoxDiscount.setSelectedItem(0);
        }
    }
    
    public void ResetValues(){
        jTextFieldNumHalf.setEnabled(false);
        jTextFieldNumQtr.setEnabled(false);
        jTextFieldNumSix.setEnabled(false);
        jTextFieldNum22.setEnabled(false);
        jTextFieldNum12.setEnabled(false);
        jTextFieldNum750.setEnabled(false);
    }

    @Action
    public void SubmitSO() {

        int response = JOptionPane.showConfirmDialog(null,
                "Are you sure you want to create a new Sales Order?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            //Setup data.
            String ItmCust = jComboBoxCustomers.getSelectedItem().toString();
            String SOCSV = "";

            String CustID = null;

            for(String s[] : Customers){
                if (s[1].equals(ItmCust)) {
                    CustID = s[0];
                }
            }

            java.util.Date dte = jDateChooser1.getDate();
            java.sql.Date SODate = new java.sql.Date( dte.getTime() );

            String[] sarry = OrderCSV.split(",");
            int count = 0;

            int NumLines = 0;

            String SNotes = "Outside SO added from app by "  + DBA.EmpFirstName + " " + DBA.EmpLastName;

            String fields = "CustID,SDate,SNotes,BeerID,NumHalf,NumQtr,NumSix,SDisc,NumTT,NumTW,NumSF";

            while (count < sarry.length){
                String query = "'" + CustID + "','" +
                        SODate + "','" +
                        SNotes + "','" +
                        sarry[count] + "','" +
                        sarry[count+1] + "','" +
                        sarry[count+2] + "','" +
                        sarry[count+3] + "','" +
                        sarry[count+4] + "','" +
                        sarry[count+5] + "','" +
                        sarry[count+6] + "','" +
                        sarry[count+7] + "'";

                count = count + 8;

                DBA.openDBCon();
                DBA.RunSQLInsertQuery("Sales",fields,query);
                //SOCSV += DBA.GetLastIndex("Sales", "SId") + ",";
                SOCSV += Integer.toString(Global.lastInsertID) + ",";

                //Update inventory.
                //DBA.ModifyInventoryFromSalesLine(DBA.GetLastIndex("Sales", "SId"));
                DBA.ModifyInventoryFromSalesLine(Integer.toString(Global.lastInsertID));
                
                DBA.closeDBCon();

                NumLines++;
            }

            //Sales Lines Added, now add list to SalesOrder Table.

            //trim last comma off of SOCSV
            String NewSOCSV = SOCSV.substring(0,SOCSV.length() - 1);

            fields = "SODate,SOPaid,SOCust,CheckNo,CheckNotes,SOCSV";
            String SOPaid = "0";
            String CheckNo = "0";
            String CheckNotes = "";
            String query = "'" + SODate + "','" +
                    SOPaid + "','" +
                    CustID + "','" +
                    CheckNo + "','" +
                    CheckNotes + "','" +
                    NewSOCSV + "'";
            DBA.openDBCon();
            DBA.RunSQLInsertQuery("SalesOrder", fields, query);
            //String LastSONum = DBA.GetLastIndex("SalesOrder", "SOId");
            String LastSONum = Integer.toString(Global.lastInsertID);
            DBA.closeDBCon();

            //Reset the data on the screen.
            SetData();
            OrderText = "";
            OrderCSV = "";
            jTextArea1.setText(OrderText);
            jComboBoxDiscount.setSelectedItem(0);

            //Call class to print sales order use LastSONum to get Sales Order.
            //TODO: Add function call.
            Global.PrintSalesOrderID = LastSONum;
            PrintSalesOrder PSO = new PrintSalesOrder();
            PSO.PrintSO();
            dispose();
        }

    }

    @Action
    public void OverRide() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will over ride existing inventory, are you sure? \n" +
                "OverRide will be logged if you continue.",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            jTextFieldNumHalf.setEnabled(true);
            jTextFieldNumQtr.setEnabled(true);
            jTextFieldNumSix.setEnabled(true);
            jTextFieldNum22.setEnabled(true);
            jTextFieldNum12.setEnabled(true);
            jTextFieldNum750.setEnabled(true);

            DBA.BIHalf = 1000000;
            DBA.BIQtr = 1000000;
            DBA.BISix = 1000000;
            DBA.BITT = 1000000;
            DBA.BITW = 1000000;
            DBA.BISF = 1000000;
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.jgoodies.looks.plastic.theme.DesertRed desertRed1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButtonOverRide;
    private javax.swing.JButton jButtonReset;
    private javax.swing.JComboBox jComboBoxBeer;
    private javax.swing.JComboBox jComboBoxCustomers;
    private javax.swing.JComboBox jComboBoxDiscount;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextFieldNum12;
    private javax.swing.JTextField jTextFieldNum22;
    private javax.swing.JTextField jTextFieldNum750;
    private javax.swing.JTextField jTextFieldNumHalf;
    private javax.swing.JTextField jTextFieldNumQtr;
    private javax.swing.JTextField jTextFieldNumSix;
    // End of variables declaration//GEN-END:variables

}
